/** @file block.h
*** @brief The data-structure for one block in the multiblock grid
**/

#ifndef _BLOCK_H_

#define _BLOCK_H_

#include "common.h"

namespace pavan{

enum zoneType { D_METRIC , C_METRIC };

template <class itype , class dtype , int dim >
  struct zoneInterface {
    /// Transformation matrix to obtain the adjacent block indices
    DECL_MAT( itype , dim ) _tmatrix;
    DECL_VEC( itype , dim ) _transform;
    /// The current blocks interface ranges
    DECL_VEC( itype , dim ) _rangeBegin;
    DECL_VEC( itype , dim ) _rangeEnd;
    /// The adjnacent blocks inteface ranges
    DECL_VEC( itype , dim ) _donorRangeBegin;
    DECL_VEC( itype , dim ) _donorRangeEnd;
    itype _donorBlockID;
    zoneType _zoneType;
};

template <class itype , class dtype , int dim >
  class block {
  public:

    void addCutBC( zoneInterface<itype,dtype,dim> &cut ) {
      _cuts.push_back( cut );
    }
 
    void setExtent( DECL_VEC( itype , dim ) &range ){
      itype buf_size = 1;
      DECL_TVEC( itype , dim ) shape;
      _extent = range;
      for( int i = 0 ; i < dim ; ++i ){
        buf_size *= _extent(i);
        shape(i) = _extent(i);
      }
      _coord.resize( shape );
    }
    
    DECL_BZ_VEC( dtype , dim ) &getCoords() {
      return _coord;
    }
    
    const DECL_TVEC( itype , dim ) &getExtent() {
      return _coord.shape();
    } 
 protected:
    itype _nInterface , _nBC;
    /// The node coordinates of the grid
    DECL_BZ_VEC( dtype , dim ) _coord;
    /// The maximum extent of the block
    DECL_VEC( itype , dim ) _extent;
    DECL_ZONE_VEC( itype , dtype , dim ) _cuts;
};

}

#endif

